/**
 * <p>
 * </p>
 *
 * @author zhuolin
 * @since 2020/5/28
 */
public class PriorityDemo {

    public static class HighPriority extends Thread {
        static int count = 0;

        @Override
        public void run() {
            while (true) {
                synchronized (PriorityDemo.class){
                    count++;
                    if(count>10000){
                        System.out.println("HighPriority is complete!");
                        break;
                    }else {
                        System.out.println("high:"+count);
                    }
                }
            }
        }
    }

    public static class LowPriority extends Thread {
        static int count = 0;

        @Override
        public void run() {
            while (true) {
                synchronized (PriorityDemo.class){
                    count++;
                    if(count>10000){
                        System.out.println("LowPriority is complete!");
                        break;
                    }else {
                        System.out.println("low:"+count);
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        Thread highPriority = new HighPriority();
        Thread lowPriority = new LowPriority();
        highPriority.setPriority(Thread.MAX_PRIORITY);
        lowPriority.setPriority(Thread.MIN_PRIORITY);
        lowPriority.start();
        highPriority.start();

    }
}
